﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;

namespace FlightClient
    {

    public enum ProgressBarDisplayText
        {

        Percentage,
        Text

        }

    public class CustomProgressBar : ProgressBar
        {

        public ProgressBarDisplayText DisplayStyle

        { get; set; }

        //public String CustomPercentage
        //{ get; set; }

        public String CustomText
        { get; set; }

        public CustomProgressBar()
            {

            SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);

            }

        protected override void OnPaint(PaintEventArgs e)
            {

            Rectangle rect = ClientRectangle;
            Graphics g = e.Graphics;

            ProgressBarRenderer.DrawHorizontalBar(g, rect);
            rect.Inflate(-3, -3);

            if (Value > 0)
                {

                Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value) / Maximum * rect.Width), rect.Height);
                ProgressBarRenderer.DrawHorizontalChunks(g, clip);

                }

            string text = DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString() + "%" : CustomText;
            using (Font f = new Font(FontFamily.GenericSerif, 10))
                {

                SizeF l = g.MeasureString(text, f);
                Point location = new Point(Convert.ToInt32(Width / 2 - l.Width / 2), Convert.ToInt32(Height / 2 - l.Height / 2));
                g.DrawString(text, f, Brushes.Black, location);

                }
            }
        }
    }